<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/10/24
  Time: 20:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="application/javascript" src="${pageContext.request.contextPath}/ztree/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="gid" class="layui-form-label">
                <span class="x-red">*</span>商品id
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gid" name="gid" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="${goods.gid}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>id
            </div>
        </div>

        <div class="layui-form-item">
            <label for="gname" class="layui-form-label">
                <span class="x-red">*</span>商品名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gname" name="gname" required=""
                       autocomplete="off" class="layui-input" value="${goods.gname}">
            </div>

        </div>

        <div class="layui-form-item">
            <label for="gprice" class="layui-form-label">
                <span class="x-red">*</span>价格
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gprice" name="gprice" required=""
                       autocomplete="off" class="layui-input" value="${goods.gprice}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="gdiscount" class="layui-form-label">
                <span class="x-red">*</span>折扣
            </label>
            <div class="layui-input-inline">
                <input type="text" id="gdiscount" name="gdiscount" required=""
                       autocomplete="off" class="layui-input" value="${goods.gdiscount}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>标签</label>
            <div class="layui-input-block">

                    <input type="radio" name="glabel" value="1" lay-skin="primary"

                    <c:if test="${goods.glabel eq 1}">
                           checked
                    </c:if>
                    >新品

                <input type="radio" name="glabel" value="2" lay-skin="primary"

                <c:if test="${goods.glabel eq 2}">
                       checked
                </c:if>
                >促销

                <input type="radio" name="glabel" value="3" lay-skin="primary"

                <c:if test="${goods.glabel eq 3}">
                       checked
                </c:if>
                >热门

                <input type="radio" name="glabel" value="-1" lay-skin="primary"

                <c:if test="${goods.glabel eq -1}">
                       checked
                </c:if>
                >暂无活动



            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>类型</label>
            <div class="layui-input-block">
                <c:forEach items="${goodstypelist}" var="goodstype">
                    <input type="radio" name="gtype" value="${goodstype.tid}" lay-skin="primary"
                    <c:if test="${goods.gtype eq goodstype.tid}">
                           checked
                    </c:if>
                    >${goodstype.tname}
                </c:forEach>

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>消费隶属</label>
            <div class="layui-input-block">
                    <input type="radio" name="gsex" value="${goods.gsex}" lay-skin="primary"
                    <c:if test="${goods.gsex eq 0}">
                           checked
                    </c:if>
                    >女装
                <input type="radio" name="gsex" value="${goods.gsex}" lay-skin="primary"
                <c:if test="${goods.gsex eq 1}">
                       checked
                </c:if>
                >男装
                <input type="radio" name="gsex" value="${goods.gsex}" lay-skin="primary"
                <c:if test="${goods.gsex eq 2}">
                       checked
                </c:if>
                >童装
                <input type="radio" name="gsex" value="${goods.gsex}" lay-skin="primary"
                <c:if test="${goods.gsex eq 3}">
                       checked
                </c:if>
                >LUOLITA
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>图片</label>
            <div class="layui-input-block">
                    <input type="file" name="gimage"  id="myfile" lay-skin="primary">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label for="gdesc" class="layui-form-label">
                描述
            </label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="gdesc" name="gdesc" class="layui-textarea">${goods.gdesc}
                </textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <button  class="layui-btn" lay-filter="add" lay-submit="" type="button" id="btn03">
                保存修改
            </button>
        </div>
    </form>
</div>
<script>
    $("#btn03").click(function () {
        var headimage=$("#myfile")[0].files[0];
       var formData = new FormData();
       formData.append("gid",$("input[name='gid']").val());
        formData.append("gname",$("input[name='gname']").val());
        formData.append("gprice",$("input[name='gprice']").val());
        formData.append("glabel",$("input[name='glabel']:checked").attr("value"));
        formData.append("gsex",$("input[name='gsex']:checked").attr("value"));
        formData.append("gtype",$("input[name='gtype']:checked").attr("value"));
        formData.append("gdesc",$("#gdesc").val());
        formData.append("gdiscount",$("input[name='gdiscount']").val());
        formData.append("himage",headimage);

        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/waresedit.do",
            processData:false,
            contentType:false,
            data:formData,
            success:function (result) {
                if (result.flag){
                    layer.msg("修改成功！",{time: 1000,icon: 6,shift: 6});
                }else{
                    layer.msg("修改失败！",{time:1000,icon:6,shift:5});
                }
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            }
        })
    })
</script>
</body>

</html>